﻿using Exam.infrastructure.EFCore;
using Exam.infrastructure.Tools;
using Exam.Service.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace Exam.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BaseController : ControllerBase
    {
        protected readonly I_Login_Service _login_Service;
        public BaseController(I_Login_Service login_Service)
        {
            _login_Service = login_Service;

        }

        /// <summary>
        /// 获取当前登录用户
        /// </summary>
        /// <returns></returns>
        protected SysUsers Get_Curr_User()
        {
            string code = this.User.Claims.ToList().First(o => o.Type == System.Security.Claims.ClaimTypes.Name).Value;
            var user = _login_Service.Check_login(code, Config.GetIp());
            return user;
        }
    }
}
